from tools_algorithm import *


class Solution:
    def countDays(self, days: int, meetings: List[List[int]]) -> int:
        meetings.sort(key=lambda a: a[0])
        range = 0
        ans = 0
        for l, r in meetings:
            if l > range:
                ans += l - range - 1
            range = max(range, r)
        ans += days - range
        return ans


s = Solution()
print(s.countDays(days=10, meetings=[[5, 7], [1, 3], [9, 10]]))


class Solution:
    def clearStars(self, s: str) -> str:
        st = set()
        q = []
        for i, v in enumerate(s):
            if v == "*":
                st.add(i)
                c, j = heappop(q)
                st.add(-j)
            else:
                heappush(q, (v, -i))
        c = []
        for i, v in enumerate(s):
            if i not in st:
                c.append(v)
        return "".join(c)


s = Solution()
print(s.clearStars("aaba*"))


class Solution:
    def minimumDifference(self, nums: List[int], k: int) -> int:
        s = set()
        ans = inf
        for num in nums:
            ans = min(ans, abs(num - k))
            t = set([num])
            for v in s:
                v |= num
                ans = min(ans, abs(v - k))
                t.add(v)
            s = t
        return ans


print(1 << 30)

ans = 0
for _ in range(1):
    c = []
    ansi = 0
    for i in range(31):
        c.append(1 << i)
        if i > 0:
            c.append(1 << (i - 1))

    s = set()
    for v in c:
        t = set([v])
        for j in s:
            t.add(j | v)
        s = t
        ansi = max(ansi, len(s))
    print(ansi)
    print(
        len(s),
        111,
    )
    for v in s:
        print(bin(v))
    ans = max(ans, ansi)
print(ans)
